package cn.krui.project.controller.system;

import cn.krui.helper.bean.AppResult;
import cn.krui.helper.bean.DataArray;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.SQL;
import cn.krui.helper.tools.MapUtils;
import cn.krui.project.bean.system.log.LoginLogInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 

import java.util.List;
import java.util.Map;

/**
 * @program: project-system
 * @description: 日志模块
 * @author: admin
 * @create: 2019-10-10 16:05
 **/
@Api(tags = "管理-日志", description = "日志模块接口")
@RestController
@RequestMapping("/system/loginlog")
@CrossOrigin
public class LoginLogsController extends SystemBaseController {

	@Autowired
	private DBHelper dbHelper;

	/**
	 * 日志列表
	 */
	@PostMapping(value = "/getLoginlogList")
	@ApiOperation(value = "获取日志列表", httpMethod = "POST")
	public AppResult<LoginLogInfo> getLoginlogList(
			@ApiParam(value = "页", required = true) @RequestParam(value = "page") String page,
			@ApiParam(value = "条", required = true) @RequestParam(value = "size") String size) {
		AppResult<LoginLogInfo> app = new AppResult<LoginLogInfo>();
		SQL.SelectSQL sql = SQL.select("*").from("qr_sys_login_logs").orderBy("create_time desc")
				.page(Integer.parseInt(page), Integer.parseInt(size));
		List<LoginLogInfo> bannerList = dbHelper.select(sql, LoginLogInfo.class);
		app.ok();
		DataArray<LoginLogInfo> list = new DataArray<LoginLogInfo>();
		list.setDataList(bannerList);
		sql.clearColumns();
		sql.select("count(1) as cnt").rows(null).offset(null);
		Map<String, Object> result = dbHelper.selectOne(sql);
		list.setDataCount(MapUtils.getInt(result, "cnt", 0));
		app.setDataArray(list);
		app.setMsg("获取成功");
		return app;
	}

}
